package edu.nf.ch01.common.exception;

import edu.nf.ch01.common.ResultVO;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author wangl
 * @date 2025/4/16
 */
@RestControllerAdvice(basePackages = "edu.nf.ch01.web.admin")
public class GlobalExceptionAdvice {

    @ExceptionHandler(GlobalException.class)
    public ResultVO handleGlobalException(GlobalException e) {
        ResultVO vo = new ResultVO();
        vo.setCode(e.getErrorCode());
        vo.setMessage(e.getMessage());
        return vo;
    }

    @ExceptionHandler(Exception.class)
    public ResultVO handleGlobalException(Exception e) {
        ResultVO vo = new ResultVO();
        vo.setCode(500);
        vo.setMessage("服务器繁忙，请稍后尝试");
        return vo;
    }
}